home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2756 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  43 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.Stanford.EDU!microunity!toms
  3. From: toms@MicroUnity.com (Tom Sanders)
  4. Subject: Re: Floating point calculation order
  5. Message-ID: <DLnE5K.2xH@microunity.com>
  6. Sender: usenet@microunity.com (news id)
  7. Organization: MicroUnity Systems Engineering, Inc.
  8. References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com>
  9. Date: Tue, 23 Jan 1996 19:00:56 GMT
  10.  
  11. In article <3104c6d9.134061184@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
  12. |> "Pavel A. Zemtsov" <PZEM@sice.nsk.su> wrote:
  13. |> 
  14. |> > 
  15. |> >  Having declaration
  16. |> > 
  17. |> >  double x, p, q, r;
  18. |> > 
  19. |> > my compiler (cc on SCO 3.2) calculated following expression:
  20. |> > 
  21. |> >  x = p * q / r;
  22. |> > 
  23. |> > as p * (q/r); (I mean, it divided first, than multiplied). That 
  24. |> > resulted in precision loss.
  25. |> > 
  26. |> > Is this legal behavior?
  27. |> 
  28. |> Not in ANSI C, but it was legal in K&R. If memory serves, it was not
  29. |> made illegal until very late in the standardizattion process so if
  30. |> your compiler was written before the standard was finalized it may not
  31. |> adhere to this.
  32. |> 
  33. |> Michael M Rubenstein
  34.  
  35. I am a firm believer in not allowing a compiler to make these decisions for
  36. me.  It's best to specify with parens the order of evaluation and not leave
  37. it up to the compiler defaults.  I would actually prefer a compiler that
  38. gave a warning if I did have an equation that could be evaluated in more
  39. than 1 order (something I have not done in over 20 years).
  40.  
  41. My opion of course,
  42. Tom Sanders
  43.